//
//  LinksViewController.m
//  MK
//
//  Created by Le Quang Vinh on 8/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "LinksViewController.h"

@interface LinksViewController ()

@end

@implementation LinksViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Links" image:[UIImage imageNamed:@"links.png"] tag:4];
        self.tabBarItem = item;
        [item release];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"Links";
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDidSelectRow:) name:@"DidSelectRow" object:nil];
    // Do any additional setup after loading the view from its nib.
    
    LinksTableViewCtrl *tbCtrl = [[LinksTableViewCtrl alloc] init];
    UITableView *tbView = tbCtrl.tableView;
    self.view = tbView;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)onDidSelectRow:(NSNotification*) noti
{
    NSString *url = [noti object];
    NSLog(@"%@", url);
    
    LinksWebviewCtrl *webCtrl = [[LinksWebviewCtrl alloc] initWithNibName:@"LinksWebviewCtrl" bundle:nil andUrl:url];
    [self.navigationController pushViewController:webCtrl animated:YES];
    [webCtrl release];
}

@end
